<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <!-- 视口配置：禁止缩放，宽度适配设备 -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>单词学习H5</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background: linear-gradient(135deg, #e8f4f8 0%, #f0f8fb 100%);
            height: 100vh;
            overflow: hidden;
        }
        .word-container {
            width: 100%;
            height: 100vh;
            padding: 20px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .word-item {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 12px;
            padding: 25px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 550px;
            height: 100%;
            display: flex;
            flex-direction: column;
            border: 1px solid rgba(255, 255, 255, 0.8);
        }
        .word-header { text-align: center; margin-bottom: 15px; }
        .word-title { 
            font-size: 28px; 
            font-weight: bold; 
            color: #409eff;
        }
        .word-content {
            flex: 1;
            overflow-y: auto; /* 内容超出时可滚动 */
            font-size: 16px;
            color: #666;
        }
        .nav-buttons {
            display: flex;
            justify-content: space-between;
            margin-top: 15px;
        }
        .nav-btn {
            padding: 12px 20px;
            border: none;
            border-radius: 8px;
            background: linear-gradient(135deg, #409eff, #67c2f9);
            color: #fff;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 8px rgba(64, 158, 255, 0.2);
        }
        .nav-btn:hover:not(:disabled) {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
        }
        .nav-btn:disabled {
            background: #ccc;
            cursor: not-allowed;
            box-shadow: none;
        }
        #rememberBtn {
            background: linear-gradient(135deg, #67c23a, #85ce61);
        }

        .word-info, .word-definition, .word-examples, .word-synonyms {
            margin-bottom: 15px;
            padding: 15px;
            background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
            border-radius: 8px;
            border-left: 3px solid #409eff;
        }
        .word-info p, .word-definition p, .word-synonyms p {
            margin: 5px 0;
        }
        .word-examples ul {
            list-style: none;
            padding: 0;
        }
        .word-examples li {
            margin: 5px 0;
            padding: 8px;
            background-color: #fff;
            border-left: 3px solid #409eff;
        }
        h3 {
            color: #333;
            font-size: 18px;
            margin-top: 0;
            padding-bottom: 5px;
            border-bottom: 1px solid #eee;
        }

        .word-info-item {
            margin-bottom: 15px;
            padding: 15px;
            background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
            border-radius: 8px;
            border-left: 3px solid #409eff;
        }
        .word-info-item h3 {
            color: #333;
            font-size: 18px;
            margin-top: 0;
            padding-bottom: 5px;
            border-bottom: 1px solid #eee;
        }
        .word-info-item p {
            margin: 5px 0;
        }
        .word-info-item ul {
            list-style: none;
            padding: 0;
        }
        .word-info-item li {
            margin: 5px 0;
            padding: 8px;
            background-color: #fff;
            border-left: 3px solid #409eff;
        }

        /* 返回按钮 */
        .back-btn {
            position: absolute;
            top: 20px;
            left: 20px;
            padding: 8px 16px;
            background: rgba(255, 255, 255, 0.9);
            border: 2px solid #409eff;
            border-radius: 8px;
            color: #409eff;
            cursor: pointer;
            transition: all 0.3s ease;
            z-index: 10;
        }
        .back-btn:hover {
            background: #409eff;
            color: white;
        }

    </style>
    <!-- 在<head>中添加以下脚本 -->
    <script>
        // 页面加载时检查登录状态（通过访问一个需要登录的接口）
        // 修改index.html中的检查登录脚本
        async function checkLogin() {
            try {
                const response = await fetch('/api/user', {
                    credentials: 'include'
                });
                if (!response.ok) {
                    window.location.href = '/login.html';
                    return false;
                }

                // 检查是否有bookId参数
                const bookId = getBookIdFromUrl();
                if (!bookId) {
                    window.location.href = '/home.html';
                    return false;
                }
                return true;
            } catch (err) {
                console.error('检查登录状态失败：', err);
                return false;
            }
        }

        function getBookIdFromUrl() {
            const params = new URLSearchParams(window.location.search);
            return params.get('bookId');
        }
        // 页面加载完成后执行检查
        window.onload = checkLogin;
    </script>
</head>
<body>
<div class="word-container">
    <button class="back-btn" onclick="window.location.href='/home.html'">← 返回</button>
    <div class="word-item" id="wordItem">
        <div class="word-header">
            <h2 class="word-title" id="wordTitle">加载中...</h2>
        </div>
        <div class="word-content" id="wordContent">
            请稍候...
        </div>
        <div class="nav-buttons">
            <button class="nav-btn" id="prevBtn" disabled>上一个</button>
            <button class="nav-btn" id="nextBtn">下一个</button>
            <button class="nav-btn" id="rememberBtn">已经记住</button>
        </div>
    </div>

</div>

<script src="script.js"></script>
</body>
</html>